//
//  BaseTableController.swift
//  sinaBlog
//
//  Created by tianxiangyang on 15/12/12.
//  Copyright (c) 2015年 itcast. All rights reserved.
//

import UIKit
import SVProgressHUD

class BaseTableController: UITableViewController,VisitorViewDelegate {
    
    var isLogin = UserAccountViewModel().userLogin
    
    let visitorView = VisitorView()
    
    
    //    override func viewWillAppear(animated: Bool) {
    //
    //        SVProgressHUD.show()
    //
    //        judgeLogin()
    //
    //    }
    
    override func loadView() {
        
        if isLogin {
        
            super.loadView()
            
        }else {
        
            visitorView.visiterViewDelegate = self
            
            setVisiterView()
            
            view = visitorView
        
        }

    }
    
//    
//    func judgeLogin() {
//        
//        if isLogin {
//            
//            SVProgressHUD.dismiss()
//            
//            view = tableView
//            
//            
//        }else{
//            
//            SVProgressHUD.dismiss()
//            
//            visitorView.visiterViewDelegate = self
//            
//            view = visitorView
//            
//        }
//        
//        
//    }
    
    
    private func setVisiterView(){
    
        self.navigationItem.leftBarButtonItem = leftBtn
        
        self.navigationItem.rightBarButtonItem = rightBtn
    
    }
    
    
    
    override func viewDidLoad() {
        
    
        
        
        
    }
    
    //抛出一个设置大图的方法
    func setLargeImage(tipLabel:String?,imageName:String?){
        
        if let name = imageName {
            
            //不是首页
            
            visitorView.circleImageView.image = UIImage(named: name)
            
            //visitorView.circleImageView.bringSubviewToFront(visitorView.backView)
            
            visitorView.backView.hidden = true
            
            visitorView.largeImageView.hidden = true
            
            visitorView.tipLabel.text = tipLabel!
            
            visitorView.circleImageView.layer.removeAllAnimations()
            
        }else{
            
            
            
        }
        
        
    }
    
    
    //MARK --接口
//    func leftBtnClick(){
//        
//        loginBtnDidClick()
//        
//        print("点击navBar上的登录按钮")
//        
//    }
//    
//    func rightBtnClick(){
//        
//        print("点击navBar上的注册按钮")
//    }
    
    
    
    func loginBtnDidClick() {
        print("点击访客视图登录按钮")
        
        let oatuthVc = OAuthController()
        
        let nav = UINavigationController(rootViewController: oatuthVc)
        
        presentViewController(nav, animated: true, completion: nil)
        
        
        
    }
    
    func registerBtnDidClick() {
        print("点击访客视图注册按钮")
    }
    
    
    lazy var leftBtn:UIBarButtonItem = {
        
        let leftBtn = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "loginBtnDidClick")
        
        //        leftBtn.title = "注册"
        
        leftBtn.setTitleTextAttributes([NSForegroundColorAttributeName:themeColor()], forState: UIControlState.Normal)
        
        return leftBtn
        
        }()
    lazy var rightBtn:UIBarButtonItem = {
        
        let rightBtn = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "registerBtnDidClick")
        
        rightBtn.setTitleTextAttributes([NSForegroundColorAttributeName: themeColor()], forState: UIControlState.Normal)
        
        return rightBtn
        
        }()
    
    
    
}
